﻿namespace SRM.DataObjects
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;

    /// <summary>
    /// Summary description for SRM_Photo
    /// </summary>
    [DataObjectAttribute(true)]
    public class SRM_Photo
    {

        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public static DataTable GetPhoto(string applicantKey)
        {
            DataTable dtResult = null;

            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                DataSet ds = new DataSet();
                SqlCommand cmd = conn.CreateCommand();
                SqlDataAdapter da = new SqlDataAdapter(cmd);

                cmd.CommandText = string.Format("SELECT * FROM SRM_ApplicantPhoto_Tbl WHERE ApplicantKey = {0};", applicantKey);
                da.Fill(ds);

                dtResult = ds.Tables[0];
            }

            return dtResult;
        } // public static DataTable GetAwards(string applicantKey)


        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public static void InsertPhoto(string applicantKey,
            string filename, byte[] fileBytes, string fileContentType, int fileSize)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "INSERT INTO SRM_ApplicantPhoto_Tbl (ApplicantKey, FileName, FileBytes, FileContentType, FileSize) VALUES (@ApplicantKey, @FileName, @FileBytes, @FileContentType, @FileSize);";
                cmd.Parameters.AddWithValue("@ApplicantKey", applicantKey);
                cmd.Parameters.AddWithValue("@FileName", filename);
                cmd.Parameters.AddWithValue("@FileBytes", fileBytes);
                cmd.Parameters.AddWithValue("@FileContentType", fileContentType);
                cmd.Parameters.AddWithValue("@FileSize", fileSize);
                
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void InsertLanguageProficiency(string applicantKey, string language, string ability, string proficiency)



        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public static void DeletePhoto(string applicantKey)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "DELETE FROM SRM_ApplicantPhoto_Tbl WHERE ApplicantKey = @AAplicantKey;";
                cmd.Parameters.AddWithValue("@ApplicantKey", applicantKey);

                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void InsertLanguageProficiency(string applicantKey, string language, string ability, string proficiency)


        //Description
        //AwardingBody
        //DateAwarded
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public static void UpdatePhoto(string applicantKey,
            string filename, byte[] fileBytes, string fileContentType, int fileSize)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = @"
UPDATE  SRM_ApplicantPhoto_Tbl 
SET     FileName = @FileName, 
        FileBytes = @FileBytes, 
        FileContentType = @FileContentType, 
        FileSize = @FileSize
WHERE   ApplicantKey = @ApplicantKey";
                cmd.Parameters.AddWithValue("@ApplicantKey", applicantKey);
                cmd.Parameters.AddWithValue("@FileName", filename);
                cmd.Parameters.AddWithValue("@FileBytes", fileBytes);
                cmd.Parameters.AddWithValue("@FileContentType", fileContentType);
                cmd.Parameters.AddWithValue("@FileSize", fileSize);

                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void UpdateAwards(string awardsKey,

    }
}